package org.tuo.service.impl;

import org.fhawk.tinyspring.ioc.annotation.inject;
import org.fhawk.tinyspring.tx.annotation.Service;
import org.fhawk.tinyspring.tx.annotation.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tuo.Mapper.StudentMapper;
import org.tuo.bean.Student;
import org.tuo.service.StudentService;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by tuo on 10/9/16.
 */
@Service
@Transaction
public class StudentServiceImpl implements StudentService {
    private Logger logger = LoggerFactory.getLogger(StudentService.class);

    @inject
    private StudentMapper mapper;


    @Override
    public void update(Student student) throws SQLException {
        mapper.update(student);
    }

    @Override
    public Student get(int id) throws SQLException {
        return mapper.get(id);
    }

    @Override
    public List<Student> findAll() throws SQLException {
        return mapper.findAll();
    }

    @Override
    public List<Map<String, Object>> findList(String name) {
        try {
            return mapper.findToList("select * from student where name = ? ", name);
        } catch (Exception e) {
            logger.error("查询学生数据失败", e);
        }
        return null;
    }
}
